<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<link rel="stylesheet" media="screen" href="css/docs.css"/>
<link rel="stylesheet" media="screen" href="lib/jqplot/jquery.jqplot.min.css"/>
<!-- jQplot SETUP -->
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/jqplot/excanvas.js"></script>
<![endif]-->
<script type="text/javascript" src="lib/jqplot/jquery.jqplot.min.js"></script>
<script type="text/javascript" src="lib/jqplot/plugins/jqplot.categoryAxisRenderer.min.js"></script>
<script type="text/javascript" src="lib/jqplot/plugins/jqplot.barRenderer.min.js"></script>
<script type="text/javascript" src="lib/jqplot/plugins/jqplot.highlighter.min.js"></script>
<script type="text/javascript" src="lib/jqplot/plugins/jqplot.dateAxisRenderer.min.js"></script>
<script type="text/javascript" src="lib/jqplot/plugins/jqplot.pointLabels.min.js"></script>
<script type="text/javascript" src="lib/jqplot/plugins/jqplot.pieRenderer.min.js"></script>
<script type="text/javascript" src="lib/jqplot/plugins/jqplot.donutRenderer.min.js"></script>
<script type="text/javascript" src="lib/jqplot/plugins/jqplot.bubbleRenderer.min.js"></script>
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css"/>

<!-- jQplot SETUP END -->

<h1 class="page-title">量化数据输入</h1>

<%@include file="/WEB-INF/pages/exam/exam_common_quan_period.jsp"%>

<%@include file="/WEB-INF/pages/exam/exam_quan_chart_period.jsp"%>

<div class="container_12 clearfix leading">
    <section class="tabs grid_6 leading">

        <header>
            <h2>未输入</h2>
        </header>
        <ul class="clearfix">

        </ul>
        <section>

            <section class="clearfix" style="display: block;">
                <header>

                </header>
                <div id="un_input_list" class="clearfix">loading...</div>
            </section>

        </section>
    </section>
    <section class="tabs grid_6 leading">
        <header>
            <h2 id="input_has_sumbit" style="display: '';">已输入 <select name="form-timezone2" id="status_sel" style="opacity: 0;" onchange="findInputForStatus(this.value)">
                <option value="-1">所有状态</option>
                <option value="wait_submit">未提交</option>
                <option value="wait_audit">未审核</option>
                <option value="pass_audit">已审核</option>
                <option value="reject_audit">审核未通过</option>
                </select>
            </h2>
        </header>
        <ul class="clearfix">

        </ul>
        <section>
            <section class="clearfix" style="display: block;">
                <header>

                </header>
                <div id="has_input_list" class="clearfix">loading...</div>
            </section>

        </section>
    </section>
</div>

<div class="clear"></div>
<div style=" padding-left:20px;display: '';" class="container_12 clearfix leading" id="subimt_div">
    <div class="form-action clearfix">
        <p>
            <a href="javascript:void(0)" onclick="submitInput()" class="button"><span class="icon" style="background:url(${ctx}/images/img/page_edit.png)">&nbsp;</span>完成打分并提交审核</a>
        </p>
    </div>
</div>
<div class="clear"></div>

<script type="text/javascript">
    $(function(){
        //loadListContent('/exam/quan_uninput_list.xhtml', 'un_input_list');	//加载未输入
        //loadListContent('/exam/quan_input_list.xhtml', 'has_input_list');	//加载已输入
        //loadControlPage();
        setTimeout("loadControlPage()", 600);
    });

    function loadListContent(url, listId) {
        if(listId == undefined){
            if(url.indexOf("quan_uninput_list") > 0){
                listId = "un_input_list";
            }else if(url.indexOf("quan_input_list") > 0){
                listId = "has_input_list";
            }
        }

        var status = null;
        var sta = $("#status_sel").val();
        if(sta != "-1"){
            status = sta;
        }

        var data = {
            "organizationId":currentSelOrgId,
            "examPeriodEnum":$("#sel_periodtype").val(),
            "examPeriodStr":$("#sel_period").val(),
            "status":status
        }

        if($("#sel_area_span select").length > 1){
            var lastSelValue = $("#sel_area_span select").last().val();
            if(lastSelValue == "-1"){
                var temp = $("#sel_area_span select").last().attr("id");
                data.organizationId = temp.substring(9, temp.length); //"sel_area-".length == 9
            }
        }

        //refreshListContent(url, data);
        $.ajax(url, {
            type:"POST",
            //data:{"organizationId":organizationId},
            data:data,
            dataType:"html",
            cache:false,
            success:function (a) {
                var obj = $("#"+listId);
                obj.html("");
                obj.html(a);
            },
            complete:function () {
            }
        });
    }

    function loadControlPage(actionUrl){
        loadListContent('/exam/quan_uninput_list.xhtml', 'un_input_list');	//加载未输入
        loadListContent('/exam/quan_input_list.xhtml', 'has_input_list');	//加载已输入
        /*
        //初始化chart
        var data = {
            "organizationId":currentSelOrgId,
            "examPeriodEnum":$("#sel_periodtype").val(),
            "examPeriodStr":$("#sel_period").val()
        }

        initChat(data.examPeriodEnum, data.examPeriodStr, data.organizationId);
        */
        $("#un_input_total").val("");
        $("#has_input_total").val("");
        initChart();
    }

    function initChart(){
        var un_input_total = $("#un_input_total").val();
        var has_input_total = $("#has_input_total").val();

        if(un_input_total >=0 && has_input_total >= 0 && un_input_total != undefined && un_input_total.length > 0 && has_input_total != undefined && has_input_total.length > 0){
            //alert(un_input_total+"-----"+has_input_total+"--------"+$("#sel_periodtype").val());
            setChatDatas(has_input_total, un_input_total, $("#sel_periodtype").val());

            if($("#sel_area").val() == "-1"){
                setSubmitInputViews(un_input_total, has_input_total);
            }
        }else{
            setTimeout("initChart()", 500);
        }
    }

    function setSubmitInputViews(un_input_total, has_input_total){
        if(true){
            return;
        }
        var data = {
            "examPeriodEnum":$("#sel_periodtype").val(),
            "examPeriodStr":$("#sel_period").val()
        }
        $.ajax("${ctx}/ajax/quan_submit_check.xhtml", {
            type:"POST",
            data:data,
            dataType:"json",
            cache:false,
            success:function (hasSubmit) {
                if(hasSubmit){
                    $("#status_sel").show();
                    $("#input_un_sumbit").hide();
                    $("#input_has_sumbit").show();
                    //$("#subimt_div").hide();
                }else{
                    $("#input_has_sumbit").hide();
                    $("#input_un_sumbit").show();
                    if(un_input_total == 0 && has_input_total > 0){
                        //$("#subimt_div").show();
                        mExamPeriodEnum = data.examPeriodEnum;
                        mExamPeriodStr = data.examPeriodStr;
                    }else{
                        //$("#subimt_div").hide();
                    }
                }
            }
        });
    }

    var mExamPeriodEnum;
    var mExamPeriodStr;
    function submitInput(){
        var data = {
            "examPeriodEnum":$("#sel_periodtype").val(),
            "examPeriodStr":$("#sel_period").val()
        }
        $.ajax("${ctx}/ajax/quan_submit_input.xhtml", {
            type:"POST",
            data:data,
            dataType:"json",
            cache:false,
            success:function (hasSubmit) {
                //alert(hasSubmit)
                if(hasSubmit){
                    alert("提交成功")
                    //$("#subimt_div").hide();
                    //location.reload();
                    window.location.href = "#exam/quan_input_main.xhtml";
                }
            }
        });
    }

    function findInputForStatus(status){
        loadListContent('/exam/quan_input_list.xhtml', 'has_input_list');	//加载已输入
    }
</script>
